home *** CD-ROM | disk | FTP | other *** search
- //***********************************************************************
- //
- // GdiDemo1.cpp
- //
- //***********************************************************************
-
- #include <afxwin.h>
- #include "GdiDemo1.h"
-
- CMyApp myApp;
-
- /////////////////////////////////////////////////////////////////////////
- // CMyApp member functions
-
- BOOL CMyApp::InitInstance ()
- {
- m_pMainWnd = new CMainWindow;
- m_pMainWnd->ShowWindow (m_nCmdShow);
- m_pMainWnd->UpdateWindow ();
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////
- // CMainWindow message map and member functions
-
- BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
- ON_WM_CREATE ()
- ON_WM_PAINT ()
- END_MESSAGE_MAP ()
-
- CMainWindow::CMainWindow ()
- {
- Create (NULL, "GdiDemo1");
- }
-
- int CMainWindow::OnCreate (LPCREATESTRUCT lpcs)
- {
- if (CFrameWnd::OnCreate (lpcs) == -1)
- return -1;
-
- TEXTMETRIC tm;
- CClientDC dc (this);
- dc.GetTextMetrics (&tm);
- m_cxChar = tm.tmAveCharWidth;
- m_cyChar = tm.tmHeight;
- return 0;
- }
-
- void CMainWindow::OnPaint ()
- {
- CPaintDC dc (this);
-
- ShowPenStyles (&dc, m_cxChar * 2, m_cyChar);
- ShowPenWidths (&dc, m_cxChar * 2, m_cyChar * 15);
- ShowBrushStyles (&dc, m_cxChar * 2, m_cyChar * 27);
- }
-
- void CMainWindow::ShowPenStyles (CDC* pDC, int x, int y)
- {
- static struct STYLES styles[] = {
- PS_SOLID, "PS_SOLID",
- PS_DASH, "PS_DASH",
- PS_DOT, "PS_DOT",
- PS_DASHDOT, "PS_DASHDOT",
- PS_DASHDOTDOT, "PS_DASHDOTDOT",
- PS_NULL, "PS_NULL",
- PS_INSIDEFRAME, "PS_INSIDEFRAME"
- };
-
- pDC->SetTextColor (RGB (0, 0, 0));
- pDC->TextOut (x, y, "Pen Styles");
-
- int dy = (m_cyChar * 3) / 2;
- int x1 = x + (m_cxChar * 2);
- int x2 = x + (m_cxChar * 22);
- int x3 = x + (m_cxChar * 46);
-
- CPen* pOldPen;
- pDC->SetTextColor (RGB (255, 0, 0));
-
- for (int i=0; i<7; i++) {
- y += dy;
- pDC->TextOut (x1, y, styles[i].szStyleName);
-
- CPen pen (styles[i].nStyle, 1, RGB (255, 0, 0));
- pOldPen = pDC->SelectObject (&pen);
-
- pDC->MoveTo (x2, y + (m_cyChar / 2));
- pDC->LineTo (x3, y + (m_cyChar / 2));
-
- pDC->SelectObject (pOldPen);
- }
- }
-
- void CMainWindow::ShowPenWidths (CDC* pDC, int x, int y)
- {
- static int nPenWidths[] = { 2, 8, 16, 24 };
-
- pDC->SetTextColor (RGB (0, 0, 0));
- pDC->TextOut (x, y, "Pen Widths");
-
- int dy = m_cyChar * 2;
- int x1 = x + (m_cxChar * 2);
- int x2 = x + (m_cxChar * 22);
- int x3 = x + (m_cxChar * 46);
-
- CPen* pOldPen;
- CString strDescription;
- pDC->SetTextColor (RGB (0, 0, 255));
-
- for (int i=0; i<4; i++) {
- y += dy;
- strDescription.Format ("%d Pixels", nPenWidths[i]);
- pDC->TextOut (x1, y, strDescription);
-
- CPen pen (PS_SOLID, nPenWidths[i], RGB (0, 0, 255));
- pOldPen = pDC->SelectObject (&pen);
-
- pDC->MoveTo (x2, y + (m_cyChar / 2));
- pDC->LineTo (x3, y + (m_cyChar / 2));
-
- pDC->SelectObject (pOldPen);
- }
- }
-
- void CMainWindow::ShowBrushStyles (CDC* pDC, int x, int y)
- {
- static struct STYLES styles[] = {
- HS_BDIAGONAL, "HS_BDIAGONAL",
- HS_CROSS, "HS_CROSS",
- HS_DIAGCROSS, "HS_DIAGCROSS",
- HS_FDIAGONAL, "HS_FDIAGONAL",
- HS_HORIZONTAL, "HS_HORIZONTAL",
- HS_VERTICAL, "HS_VERTICAL"
- };
-
- pDC->SetTextColor (RGB (0, 0, 0));
- pDC->TextOut (x, y, "Brush Styles");
-
- int dy = m_cyChar * 3;
- int x1 = x + (m_cxChar * 2);
- int x2 = x + (m_cxChar * 22);
- int x3 = x + (m_cxChar * 46);
-
- CBrush* pOldBrush;
-
- for (int i=0; i<6; i++) {
- y += dy;
- pDC->TextOut (x1, y, styles[i].szStyleName);
-
- CRect rect (x2, y - m_cyChar, x3, y + m_cyChar);
- CBrush brush (styles[i].nStyle, RGB (0, 255, 0));
-
- CPoint point (rect.left, rect.top);
- pDC->LPtoDP (&point);
- point.x %= 8;
- point.y %= 8;
- pDC->SetBrushOrg (point);
-
- pOldBrush = pDC->SelectObject (&brush);
- pDC->Rectangle (rect);
-
- pDC->SelectObject (pOldBrush);
- }
-
- y += dy;
- pDC->TextOut (x1, y, "Solid");
-
- CBrush brush (RGB (0, 255, 0));
- pOldBrush = pDC->SelectObject (&brush);
- pDC->Rectangle (x2, y - m_cyChar, x3, y + m_cyChar);
- pDC->SelectObject (pOldBrush);
- }
-